import 'dart:convert';

import 'package:flutter_app/models/response_model.dart';
import 'package:http/http.dart' as http;

class ApiService {
  static const String _baseUrl = "https://api.github.com";

  static Future<dynamic> get(String endpoint) async {
    final response = await http.get(Uri.parse("$_baseUrl/$endpoint"));
    if (response.statusCode == 200) {
      return ResponseModel.fromJson(json.decode(response.body));
    } else {
      throw Exception("Failed to load data");
    }
  }

  static Future<dynamic> post(
      String endpoint, Map<String, dynamic> body) async {
    final response =
        await http.post(Uri.parse("$_baseUrl/$endpoint"), body: body);
    if (response.statusCode == 200) {
      return ResponseModel.fromJson(json.decode(response.body));
    } else {
      throw Exception("Failed to load data");
    }
  }
}
